import torch

# ===========tensor.view演示=============
x = torch.randn(4, 4)
print(x.size())
torch.Size([4, 4])
y = x.view(16)
y.size()
print(y.size())
torch.Size([16])
z = x.view(-1, 8)  # the size -1 is inferred from other dimensions
print(z.size())
torch.Size([2, 8])

a = torch.randn(1, 2, 3, 4)
a.size()
print(a.size())
torch.Size([1, 2, 3, 4])
b = a.transpose(1, 2)  # Swaps 2nd and 3rd dimension
print(b.size())
torch.Size([1, 3, 2, 4])
c = a.view(1, 3, 2, 4)  # Does not change tensor layout in memory
print(c.size())
torch.Size([1, 3, 2, 4])
equal = torch.equal(b, c)
print(equal)

# =======torch.transpose演示:
x = torch.randn(2, 3)
transpose = torch.transpose(x, 0, 1)
print(transpose)

if __name__ == '__main__':
    print("over")
